export function formatDate(time) {
    const now = new Date();
    const diffInSeconds = Math.floor((now - new Date(time)) / 1000);
    const diffInMinutes = Math.floor(diffInSeconds / 60);
    const diffInHours = Math.floor(diffInMinutes / 60);
    const diffInDays = Math.floor(diffInHours / 24);

    if (diffInSeconds < 60) {
        return "刚刚发布";
    } else if (diffInMinutes < 60) {
        return `${diffInMinutes} 分钟前`;
    } else if (diffInHours < 24) {
        return `${diffInHours} 小时前`;
    } else if (diffInDays === 1) {
        return "昨天";
    } else if (diffInDays < 5) {
        return `${diffInDays} 天前`;
    } else {
        // 超过一个月，显示具体的日期格式
        const date = new Date(time);
        return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
    }
}